// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   DoughnutChart.java

package org.achartengine.chart;

import android.graphics.*;
import java.util.ArrayList;
import java.util.List;
import org.achartengine.model.MultipleCategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

// Referenced classes of package org.achartengine.chart:
//			RoundChart

public class DoughnutChart extends RoundChart
{

	private MultipleCategorySeries mDataset;
	private int mStep;

	public DoughnutChart(MultipleCategorySeries multiplecategoryseries, DefaultRenderer defaultrenderer)
	{
		super(null, defaultrenderer);
		mDataset = multiplecategoryseries;
	}

	public void draw(Canvas canvas, int i, int j, int k, int l, Paint paint)
	{
		paint.setAntiAlias(mRenderer.isAntialiasing());
		paint.setStyle(android.graphics.Paint.Style.FILL);
		paint.setTextSize(mRenderer.getLabelsTextSize());
		int i1 = getLegendSize(mRenderer, l / 5, 0.0F);
		int j1 = i;
		int k1 = j;
		int l1 = i + k;
		int i2 = mDataset.getCategoriesCount();
		String as[] = new String[i2];
		for (int j2 = 0; j2 < i2; j2++)
			as[j2] = mDataset.getCategory(j2);

		if (mRenderer.isFitLegend())
			i1 = drawLegend(canvas, mRenderer, as, j1, l1, j, k, l, i1, paint, true);
		int k2 = (j + l) - i1;
		drawBackground(mRenderer, canvas, i, j, k, l, paint, false, 0);
		mStep = 7;
		int l2 = Math.min(Math.abs(l1 - j1), Math.abs(k2 - k1));
		double d = 0.34999999999999998D * (double)mRenderer.getScale();
		double d1 = 0.20000000000000001D / (double)i2;
		int i3 = (int)((double)l2 * d);
		if (mCenterX == 0x7fffffff)
			mCenterX = (j1 + l1) / 2;
		if (mCenterY == 0x7fffffff)
			mCenterY = (k2 + k1) / 2;
		float f = (float)i3 * 0.9F;
		float f1 = (float)i3 * 1.1F;
		ArrayList arraylist = new ArrayList();
		for (int j3 = 0; j3 < i2; j3++)
		{
			int k3 = mDataset.getItemCount(j3);
			double d2 = 0.0D;
			String as1[] = new String[k3];
			for (int l3 = 0; l3 < k3; l3++)
			{
				d2 += mDataset.getValues(j3)[l3];
				as1[l3] = mDataset.getTitles(j3)[l3];
			}

			float f2 = 0.0F;
			RectF rectf = new RectF(mCenterX - i3, mCenterY - i3, mCenterX + i3, mCenterY + i3);
			for (int i4 = 0; i4 < k3; i4++)
			{
				paint.setColor(mRenderer.getSeriesRendererAt(i4).getColor());
				float f3 = (float)mDataset.getValues(j3)[i4];
				float f4 = (float)(((double)f3 / d2) * 360D);
				canvas.drawArc(rectf, f2, f4, true, paint);
				drawLabel(canvas, mDataset.getTitles(j3)[i4], mRenderer, arraylist, mCenterX, mCenterY, f, f1, f2, f4, j1, l1, paint);
				f2 += f4;
			}

			i3 = (int)((double)i3 - (double)l2 * d1);
			f = (float)((double)f - ((double)l2 * d1 - 2D));
			if (mRenderer.getBackgroundColor() != 0)
				paint.setColor(mRenderer.getBackgroundColor());
			else
				paint.setColor(-1);
			paint.setStyle(android.graphics.Paint.Style.FILL);
			rectf = new RectF(mCenterX - i3, mCenterY - i3, mCenterX + i3, mCenterY + i3);
			canvas.drawArc(rectf, 0.0F, 360F, true, paint);
			i3--;
		}

		arraylist.clear();
		drawLegend(canvas, mRenderer, as, j1, l1, j, k, l, i1, paint, false);
		drawTitle(canvas, i, j, k, paint);
	}

	public int getLegendShapeWidth(int i)
	{
		return 10;
	}

	public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer simpleseriesrenderer, float f, float f1, int i, Paint paint)
	{
		mStep--;
		canvas.drawCircle((f + 10F) - (float)mStep, f1, mStep, paint);
	}
}
